<template>
  <el-select
    filterable
    v-model="soft_value_"
    placeholder="请选择"
    @change="selectChange"
  >
    <el-option
      v-for="item in package_options"
      :key="item.id"
      :label="item.package_name"
      :value="item.id"
    >
    </el-option>
  </el-select>
</template>

<script>
import * as Request from "../../general/request";
import { ElMessage } from "element-plus";
import { onMounted, ref, watch } from "vue";

export default {
  name: "sys_code",
  props: {
    project_id: String,
    package_value: String,
  },
  setup(props, { emit }) {
    const package_options = ref([]);
    let soft_value_ = ref(props.package_value);

    const selectChange = (val) => {
      emit("childClick", val);
    };

    const start_query = () => {
      get_project_package();
    };

    watch(props, (new_val) => {
      soft_value_.value = new_val.package_value;
    });

    const get_project_package = async () => {
      const response = await Request.GET(
        "/background/home/resource_management/project_package",
        { project_id: props.project_id }
      );
      if (response && response.data) {
        var return_data = response.data;
        if (return_data.success) {
          package_options.value = return_data.data;
        } else {
          ElMessage.error(return_data.msg);
        }
      }
    };

    onMounted(start_query);

    return {
      selectChange,
      package_options,
      soft_value_,
    };
  },
};
</script>

<style scoped></style>
